/**
 * Created by gongxun on 16/11/18.
 */

var KwxHornHelper = function(Image_horn){
    var that = {};

    that.Image_horn = null;

    that.Text_horn = null;

    that.historyList = null;

    //推荐的微信号
    that.customerWX = "";

    that.setHornText = function(texts){
        // mo.gameHelper.setTextString(that.Text_horn, text);
        // that.startHornAction();
        for (var i = 0; i < texts.length; i++){
            if (that.historyList.length > 50){
                continue;
            }
            that.historyList.push(texts[i]);
        }
    };

    that.startHornAction = function(){
        var moveSize = mo.seekWidgetByName(that.Image_horn, "Panel_horn").getContentSize();

        mo.gameHelper.setTextString(that.Text_horn, that.getItemContent());
        var dis = that.Text_horn.getContentSize().width + moveSize.width;
        var speed = 100;
        var time = dis / speed;

        that.Text_horn.stopAllActions();
        that.Text_horn.setPosition(cc.p(moveSize.width, moveSize.height / 2));
        that.Text_horn.runAction(cc.sequence(
            cc.moveTo(time, cc.p(-that.Text_horn.getContentSize().width, moveSize.height / 2)),
            cc.delayTime(0.5),
            cc.callFunc(that.startHornAction)
        ));
    };

    that.getItemContent = function(){
        if (that.historyList.length == 0){
            var insertTexts = that.getHornNullMsg();
            that.setHornText(insertTexts);
        }
        var content = that.historyList.shift();
        return content;
    };

    that.startAction = function(){
        that.startHornAction();
    };

    that.endAction = function(){
        that.Text_horn.stopAllActions();
    };

    that.init = function(){
        that.Image_horn = Image_horn;
        that.Text_horn = mo.seekWidgetByName(that.Image_horn, "Text_horn");
        that.historyList = [];
    };

    that.getHornNullMsg = function(){
        var insertTexts = [
            "请各位玩家文明娱乐,远离赌博,如发现有赌博行为将封停账号,并向公安机关举报！"
        ];

        if (that.customerWX != ""){
            insertTexts.push(that.customerWX);
        }
        return insertTexts;
    };

    that.init();

    return that;
};